import 'package:flutter/widgets.dart';

import 'package:auto_route/auto_route.dart';
import 'package:forui/forui.dart';

import 'package:forui_samples/sample.dart';

@RoutePage()
class TooltipPage extends StatelessWidget {
  final FThemeData theme;
  final bool hover;
  final bool longPress;
  final Axis axis;

  TooltipPage({
    @queryParam String theme = 'zinc-light',
    @queryParam String hover = 'true',
    @queryParam String longPress = 'true',
    @queryParam String axis = 'vertical',
  }) : theme = themes[theme]!,
       hover = bool.tryParse(hover) ?? true,
       longPress = bool.tryParse(longPress) ?? true,
       axis = switch (axis) {
         'horizontal' => Axis.horizontal,
         _ => Axis.vertical,
       };

  @override
  Widget build(BuildContext context) => FTheme(
    data: theme,
    child: FScaffold(
      child: Center(
        child: ConstrainedBox(
          constraints: const BoxConstraints(maxWidth: 200, maxHeight: 200),
          child: Builder(
            builder: (context) => Column(
              mainAxisAlignment: .center,
              children: [
                const SizedBox(height: 30),
                FTooltip(
                  hover: hover,
                  longPress: longPress,
                  tipAnchor: axis == .horizontal ? .topLeft : .bottomCenter,
                  childAnchor: axis == .horizontal ? .topRight : .topCenter,
                  tipBuilder: (context, _) => const Text('Add to library'),
                  child: FButton(
                    style: FButtonStyle.outline(),
                    mainAxisSize: MainAxisSize.min,
                    onPress: () {},
                    child: Text([if (longPress) 'Long press', if (hover) 'Hover'].join('/')),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  );
}
